package algotithm.leetcode.stack.test1700;

/**
 * @author 25068
 * @Date 2021/5/8 10:44
 * @Title 1700. 无法吃午餐的学生数量
 */
public class Solution {

    public static void main(String[] args) {
        int[] students = {1,1,0,0};
        int[] sandwiches = {0,1,0,1};
        Solution solution = new Solution();
        int i = solution.countStudents(students, sandwiches);
        System.out.println(i);
    }

    public int countStudents(int[] students, int[] sandwiches) {
        if (students == null || students.length == 0) {
            return 0;
        }
        if (sandwiches == null || sandwiches.length == 0) {
            return students.length;
        }
        // stuLike[0] 喜欢圆形的学生数，stuLike[1]喜欢方形的学生数
        int[] stuLike = new int[2];
        for (int student : students) {
            stuLike[student]++;
        }
        for (int i = 0; i < sandwiches.length; i++) {
            if (stuLike[sandwiches[i]] == 0) {
                // 学生是转圈来的，此时说明喜欢圆形或者方形的学生已经没有了，顶部的三明治没人取走了。
                break;
            }
            // 对应的学生满足一个，减少一个
            stuLike[sandwiches[i]]--;
        }
        return stuLike[0] + stuLike[1];
    }
}


